home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / cwkfile.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  3KB  |  96 lines

  1.  
  2.  
  3. /*
  4.     GWMON Parallel Ada Monitor for 386/486 PCs   
  5.     Copyright (C) 1993, Charles W. Kann  & Michael Bliss Feldman
  6.                         ckann@seas.gwu.edu mfeldman@seas.gwu.edu
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. */
  22.  
  23. #include "ed.h"
  24.  
  25. struct FL {
  26.     FILE_REC_PTR FD;
  27.     struct FL *nxt;    
  28.     } FILE_LIST, *FILE_LIST_PTR;
  29.  
  30.  
  31. FILE_REC_PTR CWK_LOAD_FILE( file_name )
  32. char *file_name;
  33. {
  34.     int ch;
  35.     FILE_REC_PTR tmp_fn;
  36.     char buffer[100], msg[100];
  37.     int line_cnt = 0, length;
  38.     static struct FL *First_FL = NULL, *Next_FL;
  39.  
  40.     /*  
  41.     Only allocate a new file if the current one is not open.
  42.     */
  43.  
  44.     Next_FL = First_FL;
  45.  
  46.     /************************************************************************/
  47.     /*    This is a way to deal with seperate compilations of package       */
  48.     /*      specifications and bodies.  If the specification is in a ".ads"   */
  49.     /*    file, and the body in a ".adb" file, then always open the ".abd"  */
  50.     /*    file.                                    */
  51.     /************************************************************************/
  52.  
  53.     length = strlen( file_name );
  54.     if ( strncmp( &file_name[length-3], "ads", 3 ) == 0 )
  55.     strcpy( &file_name[length-3], "adb" );
  56.  
  57.     while (  Next_FL != NULL )
  58.     {
  59.         if ( ! strcmp( Next_FL->FD->FN, file_name ) ) 
  60.             return Next_FL->FD;
  61.     Next_FL = Next_FL->nxt;
  62.     }
  63.  
  64.     Next_FL = malloc( sizeof( FILE_LIST ) );
  65.     Next_FL->nxt = First_FL;
  66.     First_FL = Next_FL;
  67.  
  68.     tmp_fn = malloc( sizeof( FILE_REC ));
  69.     Next_FL->FD = tmp_fn;
  70.     tmp_fn->FN = malloc( strlen( file_name )+1 );
  71.     strcpy( tmp_fn->FN, file_name );
  72.  
  73.     tmp_fn->fd = fopen( tmp_fn->FN, "r" );
  74.     if (tmp_fn->fd == 0) {
  75.         sprintf( msg, "Can't open file %s", file_name );
  76.     CWK_CLEANUP_MON( -1, msg );
  77.     }
  78.     
  79.     while ( fgets( buffer, 100, tmp_fn->fd ) ) {
  80.     if ( line_cnt >= MAX_LINES )
  81.     {
  82.             sprintf( msg, "Too many lines in file %s", file_name );
  83.         CWK_CLEANUP_MON( -1, msg );
  84.     }
  85.  
  86.     tmp_fn->lines[line_cnt] = malloc( strlen(buffer));
  87.         if (tmp_fn->lines[line_cnt] == 0) {
  88.             CWK_CLEANUP_MON( -1,"Out of memory" );
  89.         }
  90.     strncpy( tmp_fn->lines[line_cnt], buffer, strlen( buffer ) - 1 );
  91.     tmp_fn->lines[line_cnt++][strlen(buffer)-1] = '\0';
  92.     }
  93.     tmp_fn->lines_in_file = line_cnt - 1;
  94.     return tmp_fn;
  95. }
  96.